package com.atguigu.crowd.mvc.handler;

import com.atguigu.crowd.entity.Admin;
import com.atguigu.crowd.service.AdminService;
import com.atguigu.crowd.util.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author zwj
 * @create 2021-07-02-13:23
 */
@Controller
public class TestHandler {
    @Autowired
    private AdminService adminService;

    @Autowired
    private BCryptPasswordEncoder bCryptPasswordEncoder;
    @ResponseBody
    @RequestMapping("/test1")
    public String testReceiveArrayOne(){
        return bCryptPasswordEncoder.encode("123456");
    }
    //采用实体类的方式，getset方法，我就不试了，繁琐，不采用
    @ResponseBody
    @RequestMapping("/send/array/two.html")
    public String testReceiveArrayTwo(){
        return "success";
    }

    @ResponseBody
    @RequestMapping("/send/array/three.html")
    public String testReceiveArrayThree(@RequestBody List<Integer> array){
        if (array != null)
        {
            // 接收参数时需要在参数名后面加[]
            for (Integer number : array){
                System.out.println(number);
            }
        }
        return "success";
    }
    @ResponseBody
    @RequestMapping("/test/ssm.html")
    public ResultEntity<Object> testSSM(ModelMap modelMap,Exception exception){
        List<Admin> adminList = adminService.getAll();
        modelMap.addAttribute("adminList",adminList);
        System.out.println(1/10);
        return ResultEntity.failed(exception.getMessage());
    }
}
